

typedef unsigned char T_UBYTE;
#pragma config FOSC = INTOSCIO_EC //Internal oscillator, port function on RA6, EC used by USB 
#pragma config WDT = OFF //Disable watchdog timer

#define SLEEP Delay10KTCYx(deFuzzy(ADRESH))
#define WAIT_CONVERSION ADCON0bits.GO_DONE = 1;//Start A/D Conversion\
while(ADCON0bits.GO_DONE );//Loop here until A/D conversion completes
#define c_input_port PORTB 
#define c_output_port LATD
unsigned char deFuzzy(unsigned char ADCResult);

unsigned char ra_transitions[32]=
{1,0,7,0,
 2,1,0,1,
 3,2,1,2,
 4,3,2,3,
 5,4,3,4,
 6,5,4,5, 
 7,6,5,6, 
 0,7,6,7
};

unsigned char power(unsigned char state)
{
	switch(state)
	{
	case 0:
	return 1;
	break;

	case 1:
	return 2;
	break;

	case 2:
	return 4;
	break;

	case 3:
	return 8;
	break;

	case 4:
	return 16;
	break;

	case 5:
	return 32;
	break;

	case 6:
	return 64;
	break;

	case 7:
	return 128;
	break;

	default:
	return 255;
	break;
	}	
}

unsigned char deFuzzy(unsigned char ADCResult)
{

return (32*(unsigned char)((ADCResult+1)/32)-1);
}

#include <p18f4550.h>
#include <delays.h>
